<?php

namespace App\Http\Controllers;

use App\Http\Model\FriendBrowses;
use App\Http\Model\Friends;
use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use Illuminate\Http\Request;
use App\Lib\Response;

/**
 * 足迹/访客（新）v2.2.9
 */
class FootprintController extends BaseController
{
    /**
     * 足迹列表
     *
     * @param Request $request
     */
    public function index(Request $request)
    {
        $userId = $request->input('user_id', 0);//前端传输的用户id
        if (!$userId) {
            $userId = $this->getLoginUserId();//从header中获取
        }

        if (!$userId) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $model = new FriendBrowses();
        $data = $model->formatUserStatisticsData($model->getUserFootprintStatisticsData($userId, 30));
        Response::returnResult(Hint::SUCCESS, $data);
    }

    /**
     * 访客列表
     *
     * @param Request $request
     */
    public function visitors(Request $request)
    {
        $userId = $request->input('user_id', 0);//前端传输的用户id
        if (!$userId) {
            $userId = $this->getLoginUserId();//从header中获取
        }

        if (!$userId) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $model = new FriendBrowses();
        $data = $model->formatUserStatisticsData($model->getUserVisitorsStatisticsData($userId, 30));
        (new Friends())->reset_redis_visitor_number($userId);//清空访客浏览数
        Response::returnResult(Hint::SUCCESS, $data);
    }
}